//
//  BCMineChargeWeekCollectionViewCell.m
//  BangcaiSale
//
//  Created by Liang Zhang on 16/7/11.
//  Copyright © 2016年 Bangcai. All rights reserved.
//

#import "BCMineChargeWeekCollectionViewCell.h"

@interface BCMineChargeWeekCollectionViewCell ()
@property (nonatomic, strong) NSDate *weekStart;
@property (nonatomic, strong) NSDate *weekEnd;
@end

@implementation BCMineChargeWeekCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    NSInteger currentWeekDay = [BCDateTool weekDay:[NSDate date]];
    _weekStart = [BCDateTool GetDayWithIndex:(1-currentWeekDay) From:[NSDate date]];
    _weekEnd = [BCDateTool GetDayWithIndex:(7-currentWeekDay) From:[NSDate date]];
    _weekDuringLable.text = [NSString stringWithFormat:@"%@-%@",
                             [BCDateTool dateStringFromDate:_weekStart],
                             [BCDateTool dateStringFromDate:_weekEnd]];
    [self nextWeekGo];
}

+ (instancetype)cellWithCollectionView:(UICollectionView *)collectionView {
    static NSString *ID = @"MineChargeWeekCellIdentifer";
    UINib *nib = [UINib nibWithNibName:@"BCMineChargeWeekCollectionViewCell" bundle: [NSBundle mainBundle]];
    [collectionView registerNib:nib forCellWithReuseIdentifier:ID];
    BCMineChargeWeekCollectionViewCell *cell = [[BCMineChargeWeekCollectionViewCell alloc] init];
    return cell;
}

- (IBAction)lastWeekAction:(UIButton *)sender {
    _weekStart = [BCDateTool GetDayWithIndex:-7 From:_weekStart];
    _weekEnd = [BCDateTool GetDayWithIndex:-7 From:_weekEnd];
    _weekDuringLable.text = [NSString stringWithFormat:@"%@-%@",
                             [BCDateTool dateStringFromDate:_weekStart],
                             [BCDateTool dateStringFromDate:_weekEnd]];
    [self nextWeekGo];
    _weekBlock(_weekStart,_weekEnd);
}

- (IBAction)nextWeekAction:(UIButton *)sender {
    [sender setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _weekStart = [BCDateTool GetDayWithIndex:7 From:_weekStart];
    _weekEnd = [BCDateTool GetDayWithIndex:7 From:_weekEnd];
    _weekDuringLable.text = [NSString stringWithFormat:@"%@-%@",
                             [BCDateTool dateStringFromDate:_weekStart],
                             [BCDateTool dateStringFromDate:_weekEnd]];
    [self nextWeekGo];
    _weekBlock(_weekStart,_weekEnd);
}

-(void)nextWeekGo {
    if (_weekEnd.timeIntervalSince1970<=[NSDate date].timeIntervalSince1970) {
        _nextWeekLable.textColor = [UIColor darkTextColor];
        _nextWeekButton.userInteractionEnabled = YES;
    }
    else {
        _nextWeekLable.textColor = [UIColor lightGrayColor];
        _nextWeekButton.userInteractionEnabled = NO;
    }
}

@end
